import Vue from 'vue'
import Router from 'vue-router'
import Home from './views/Home.vue' // 登录
import navIndex from './views/nav.vue' // 引导页
import store from 'store/index'

/* 报警中心 */
import AlertCenter from './views/alarm-center/index.vue'
import ConfigurationCenter from './views/alarm-center/components/configuration-center.vue'
import AlarmStatistics from './views/alarm-center/components/alarm-statistics.vue'
import DataCenter from './views/alarm-center/components/data-center.vue'

/* 监管座舱 */
import SupervisionCabin from  './views/supervision-cabin/index.vue'
import ScreenInfo from  './views/supervision-cabin/components/screen-info.vue' // 监管大屏
import SDataCenter from  './views/supervision-cabin/components/s-data-center.vue' // 数据中心
import HeatSourceInfo from  './views/supervision-cabin/components/heat-source-info.vue' // 供热信息
import HotSites from  './views/supervision-cabin/components/hot-sites.vue' // 换热站
import HotEnterprise from  './views/supervision-cabin/components/hot-enterprise' // 热企
import HotCrew from  './views/supervision-cabin/components/hot-crew' // 机组
import HotUnit from  './views/supervision-cabin/components/hot-unit' // 单元
import HotHome from  './views/supervision-cabin/components/hot-home' // 户
import HotSource from  './views/supervision-cabin/components/hot-source' // 热源

/* 调控管家 */
import RegulationHousekeeper from './views/regulation-housekeeper/index.vue'
import SmartSet from './views/regulation-housekeeper/components/smart-set.vue'
import RegulationSet from './views/regulation-housekeeper/components/regulation-set.vue'

/* 天气 */
import Weather from './views/weather/index.vue'
import WeatherInfo from './views/weather/components/weather-info'

Vue.use(Router);

const routes = [{
        path: '/home',
        name: 'home',
        component: Home,
        meta: {
            auth: false, // 是否需要登录
            keepAlive: true // 是否缓存组件
        }
    },{
            path: '/',
            name: 'navIndex',
            component: navIndex,
        meta: {
            auth: true,
            keepAlive: true
        }
    },{
    path: '/weather', // 天气
    name: 'weather',
    component: Weather, // 告警中心路由入口
    redirect: '/weather/weather-info',
    children: [{
        path: 'weather-info',
        name: 'weather-info',
        component: WeatherInfo, // 配置中心
        meta: {
            auth: false, // 是否需要登录
            keepAlive: true // 是否缓存组件
        }
    }]
}, {
        path: '/alert-center', // 告警中心
        name: 'alert-center',
        component: AlertCenter, // 告警中心路由入口
        redirect: '/alert-center/data-center',
        children: [{
            path: 'configuration-center',
            name: 'ConfigurationCenter',
            component: ConfigurationCenter, // 配置中心
            meta: {
                auth: false, // 是否需要登录
                keepAlive: true // 是否缓存组件
            }
        }, {
            path: 'alarm-statistics',
            name: 'AlarmStatistics',
            component: AlarmStatistics, // 告警统计
            meta: {
                auth: false, // 是否需要登录
                keepAlive: true // 是否缓存组件
            }
        }, {
            path: 'data-center',
            name: 'DataCenter',
            component: DataCenter, // 数据中心
            meta: {
                auth: false, // 是否需要登录
                keepAlive: true // 是否缓存组件
            }
        }],
        meta: {
            auth: false, // 是否需要登录
            keepAlive: false// 是否缓存组件
        }
    },
{
    path: '/regulation-housekeeper', // 调控管家
    name: 'RegulationHousekeeper',
    component: RegulationHousekeeper,
    redirect: '/regulation-housekeeper/smart-set',
    children: [{
        path: 'smart-set',
        name: 'SmartSet',
        component: SmartSet, // 智慧化调控
        meta: {
            auth: false, // 是否需要登录
            keepAlive: true // 是否缓存组件
        }
    }, {
        path: 'regulation-set',
        name: 'RegulationSet',
        component: RegulationSet, // 调控设置
        meta: {
            auth: false, // 是否需要登录
            keepAlive: true // 是否缓存组件
        }
    }],
    meta: {
        auth: false, // 是否需要登录
        keepAlive: false// 是否缓存组件
    }
},
{
    path: '/supervision-cabin', // 监管座舱
    name: 'supervision-cabin',
    component: SupervisionCabin,
    children: [{
        path: 'screen-info',
        name: 'ScreenInfo',
        component: ScreenInfo, // 监管大屏
        meta: {
            auth: false, // 是否需要登录
            keepAlive: true // 是否缓存组件
        }
    }, {
        path: 'heat-source-info',
        name: 'HeatSourceInfo',
        component: HeatSourceInfo, // 供热系统信息
        meta: {
            auth: false, // 是否需要登录
            keepAlive: true // 是否缓存组件
        }
    }, {
        path: 's-data-center',
        name: 'SDataCenter',
        component: SDataCenter, // 数据中心
        meta: {
            auth: false, // 是否需要登录
            keepAlive: true // 是否缓存组件
        }
    }, {
        path: 'hot-sites',
        name: 'HotSites',
        component: HotSites, // 数据中心
        meta: {
            auth: false, // 是否需要登录
            keepAlive: true // 是否缓存组件
        }
    }, {
        path: 'hot-enterprise',
        name: 'HotEnterprise',
        component: HotEnterprise, // 热企
        meta: {
            auth: false, // 是否需要登录
            keepAlive: true // 是否缓存组件
        }
    }, {
        path: 'hot-crew',
        name: 'HotCrew',
        component: HotCrew, // 机组
        meta: {
            auth: false, // 是否需要登录
            keepAlive: true // 是否缓存组件
        }
    }, {
        path: 'hot-unit',
        name: 'HotUnit',
        component: HotUnit, // 单元
        meta: {
            auth: false, // 是否需要登录
            keepAlive: true // 是否缓存组件
        }
    },{
        path: 'hot-home',
        name: 'HotHome',
        component: HotHome, // 户
        meta: {
            auth: false, // 是否需要登录
            keepAlive: true // 是否缓存组件
        }
    },{
        path: 'hot-source',
        name: 'HotSource',
        component: HotSource, // 热源
        meta: {
            auth: false, // 是否需要登录
            keepAlive: true // 是否缓存组件
        }
    }],
    meta: {
        auth: false, // 是否需要登录
        keepAlive: false// 是否缓存组件
    }
}
]

const router = new Router({
    routes,
    mode: 'history',
    linkActiveClass: 'active'
});

// 全局路由钩子函数 对全局有效
router.beforeEach((to, from, next) => {
    let auth = to.meta.auth
    let token = store.state.tokenKey;

    if (auth) { // 需要登录
        if (token) {
            next()
        } else {
            next({
                path: '/home'
            })
        }
    } else {
        next()
    }
});
export default router
